Skip to content

fix(functions): keep an attached debugger's breakpoints working on Python < 3.12 - #2000

Open
RaresUiPath wants to merge 1 commit into
mainfrom
fix/functions-debug-keep-debugger-tracer
Open

RaresUiPath wants to merge 1 commit into
mainfrom
fix/functions-debug-keep-debugger-tracer

Conversation

@RaresUiPath

Copy link
Copy Markdown
Contributor

Problem

On Python 3.11, breakpoints in a function are never hit when it runs with uipath run --debug and VS Code attaches with "Python: Remote Attach" (debugpy). The breakpoint shows as verified, the function runs to the end, and debugpy prints:

PYDEV DEBUGGER WARNING:
sys.settrace() should not be used when the debugger is being used.
This may cause the debugger to stop working correctly.
Call Location:
  File ".../uipath/functions/debug.py", line 350, in _run
    sys.settrace(self._trace_callback)

Cause

UiPathDebugFunctionsRuntime.stream() runs the function on a worker thread with its own sys.settrace hook whenever the entrypoint has a call graph. It does this to emit state events for the graph nodes, even when no breakpoints are set. Before Python 3.12, pydevd-based debuggers such as debugpy also trace threads through sys.settrace, so our hook replaces the debugger's on that thread. From Python 3.12, debugpy uses sys.monitoring and isn't affected.

Fix

If no breakpoints were requested and the current thread is traced by a pydevd-based debugger, skip the call-graph state events. The function then runs without our trace function, in the thread the debugger already traces.

  • Breakpoints requested through the debug bridge still use our trace function, as before.
  • Nothing changes when no debugger is attached, or on Python 3.12+, where sys.gettrace() is empty under debugpy.
  • Coverage's trace function isn't treated as a debugger, so tests under pytest --cov keep today's behavior.

The local run command forwards only UPDATED state events, so it loses nothing. A debug bridge that renders the call graph won't get per-function events while a settrace-based debugger is attached.

Testing

  • New TestAttachedDebugger tests in tests/functions/test_debug_breakpoints.py:
    • With a pydevd-style trace function installed, that trace function still sees every call of the function. This test fails without the fix.
    • Debug-bridge breakpoints still pause.
    • Call-graph state events are skipped.
    • Only pydevd trace functions are recognized, not coverage's.
  • pytest tests/functions: 65 passed.
  • Full uipath package suite on Python 3.11: 2735 passed. One local failure, test_new.py::TestUipathScaffoldPin, comes from older installed uipath metadata in the local environment and is unrelated.
  • Manual check on Python 3.11 with debugpy 1.8.22: ran uipath run main '{"n": 21}' --debug with a breakpoint in a helper that the entrypoint calls.
    • Before: it never stopped, and debugpy printed 2 warnings.
    • After: it stopped at the breakpoint, printed no warnings, and returned the same output.
  • ruff check, ruff format --check and mypy pass on the changed files.

Bumps uipath to 2.15.3.

🤖 Generated with Claude Code

…thon < 3.12

The functions debug runtime runs a function on a worker thread with its own
sys.settrace hook whenever the entrypoint has a call graph, to emit state
events, even when no breakpoints are set. Before Python 3.12, pydevd-based
debuggers such as debugpy trace threads through sys.settrace too, so with
`uipath run --debug` the runtime replaced the debugger's hook on that thread:
breakpoints were verified but never hit, and debugpy warned that
sys.settrace() should not be used while debugging.

Without breakpoints of our own, skip the call-graph state events while a
pydevd trace function is active, so the function runs in the thread the
debugger traces. Breakpoints requested through the debug bridge keep the
current behavior, and nothing changes from Python 3.12, where debugpy uses
sys.monitoring, or under coverage tools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 11:12
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-runtime test:uipath-integrations labels Nov 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the attached-debugger tracing change.

No open issues 🎉

What changed in this PR

Preserves attached pydevd-based debugger breakpoints on Python versions before 3.12 by avoiding the SDK’s trace hook when no debug-bridge breakpoints are requested.

Changes:

  • Skips call-graph state tracing when a pydevd tracer is active, while retaining debug-bridge breakpoint behavior.
  • Adds regression tests for debugger tracing, breakpoint pauses, state-event suppression, and tracer detection.
  • Bumps uipath to version 2.15.3.
File Description
packages/​uipath/​uv.lock Updates the locked local package version to 2.15.3.
packages/​uipath/​tests/​functions/​test_debug_breakpoints.py Adds attached-debugger regression tests.
packages/​uipath/​src/​uipath/​functions/​debug.py Detects pydevd tracers and bypasses optional call-graph tracing.
packages/​uipath/​pyproject.toml Bumps the package version to 2.15.3.

Review effort: Balanced

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants